<?php 
defined('IN_TS') or die('Access Denied.');
//商品类型

$typeid = intval($_GET['id']);

$page = isset($_GET['page']) ? intval($_GET['page']) : 1;

$lstart = $page*12-12;


if(!$TS_USER['userid']){
	$TS_USER['userid']=0;
}



if($typeid == 0){

	$url = tsUrl('gift','type',array('page'=>''));
	$arr = 'isaudit=0 and (status>-1 or (status=-1 and userid='.$TS_USER['userid'].'))';
	$giftNum = $new['gift']->findCount('gift',array('isaudit'=>0));
	
	$title = '全部商品';

}else{

	$strType = $new['gift']->find('gift_type',array(
		'typeid'=>$typeid,
	));

	$url = tsUrl('gift','type',array('id'=>$typeid,'page'=>''));
	$arr = 'typeid='.$typeid.' and isaudit=0 and (status>-1 or (status=-1 and userid='.$TS_USER['userid'].'))';
	
	$giftNum = $new['gift']->findCount('gift',$arr);

	$title = $strType['typename'];
	
}

$pageUrl = pagination($giftNum, 12, $page, $url);

$arrGifts = $new['gift']->findAll('gift',$arr,'addtime desc',null,$lstart.',12');
foreach($arrGifts as $key=>$item){

	$arrGift[] = $item;
	$arrGift[$key]['title'] = htmlspecialchars($item['title']);
	$arrGift[$key]['address'] = htmlspecialchars($item['address']);
	$arrGift[$key]['user'] = aac('user')->getOneUser($item['userid']);

	switch($item['status']){
		case '-1':
			$arrGift[$key]['status1'] = '下架';
			break;
		case '0':
			$arrGift[$key]['status1'] = '待售';
			break;
		case '1':
			$arrGift[$key]['status1'] = '售磬';
			break;
	}
}
include template("type");